/*
 * Powered By fanrenqij.com
 * Since 2017 - 2017
 */

package com.fanrenqiji.modules.business.feedbackdetail.web;


import com.fanrenqiji.common.config.GlobalSetting;
import com.fanrenqiji.common.persistence.Page;
import com.fanrenqiji.common.web.BaseController;
import com.fanrenqiji.modules.business.feedbackdetail.service.FeedbackDetailService;
import com.fanrenqiji.modules.business.feedbackdetail.vo.FeedbackDetailVO;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value = "${adminPath}/business/feedbackdetail")
public class FeedbackDetailController extends BaseController {
	
    private static Logger log = LoggerFactory.getLogger(FeedbackDetailController.class);
    @Autowired
	private FeedbackDetailService feedbackDetailService;

@ModelAttribute("feedbackDetail")
public FeedbackDetailVO getFeedbackDetail(@RequestParam(required = false) String id){
	if(StringUtils.isNotEmpty(id)){
		return feedbackDetailService.get(id);
	}else{
		return new FeedbackDetailVO();
	}
}

/**
 * 列表
 *
 * @return
 */
@RequiresPermissions("business:feedbackdetail:view")
@RequestMapping(value = {"list", ""})
public String list(FeedbackDetailVO feedbackDetail, HttpServletRequest request,
                   HttpServletResponse response, Model model){
	Page<FeedbackDetailVO> page = feedbackDetailService.findFeedbackDetailByPage(new Page<FeedbackDetailVO>(request,response),
		feedbackDetail);
	model.addAttribute("page",page);
	model.addAttribute("feedbackDetail",feedbackDetail);
	return"modules/business/feedbackdetail/feedbackdetailList";
}

/**
 * 选择列表
 *
 * @return
 */
@RequestMapping(value = "select")
public String select(FeedbackDetailVO feedbackDetail, HttpServletRequest request, HttpServletResponse response, Model model){
	Page<FeedbackDetailVO> page = feedbackDetailService.findFeedbackDetailByPage(new Page<FeedbackDetailVO>(request,response,10),feedbackDetail);
	model.addAttribute("page",page);
	model.addAttribute("feedbackDetail",feedbackDetail);
	return"modules/business/feedbackdetail/feedbackdetailSelect";
}

/**
 * 用户添加更新表
 *
 * @param model
 * @return
 */
@RequiresPermissions("business:feedbackdetail:view")
@RequestMapping(value = "form")
public String form(Model model,FeedbackDetailVO feedbackDetail){
	if (StringUtils.isNotEmpty(feedbackDetail.getId())) {
		model.addAttribute("feedbackDetail", feedbackDetailService.get(feedbackDetail.getId()));
	}else{
		model.addAttribute("feedbackDetail",feedbackDetail);
	}
	return"modules/business/feedbackdetail/feedbackdetailForm";
}

/**
 * 添加或修改提交
 *
 * @param feedbackDetail
 * @param model
 * @param redirectAttributes
 * @return
 */
@RequiresPermissions("business:feedbackdetail:edit")
@RequestMapping(value = "save")
public String save(FeedbackDetailVO feedbackDetail, Model model,
                   RedirectAttributes redirectAttributes){// TODO @Valid 添加后端校验
	if(!beanValidator(model,feedbackDetail)){
		return form(model,feedbackDetail);
	}
	feedbackDetailService.update(feedbackDetail);
	addMessage(redirectAttributes,"保存成功");
	return"redirect:"+ GlobalSetting.getAdminPath()
		+"/business/feedbackdetail/?repage";
}

/**
 * 删除操作
 *
 * @return
 */
@RequestMapping("delete")
@RequiresPermissions("business:feedbackdetail:edit")
public String delete(String id, RedirectAttributes redirectAttributes) {
	feedbackDetailService.delete(id);
	addMessage(redirectAttributes, "删除成功");
	return "redirect:" + GlobalSetting.getAdminPath() + "/business/feedbackdetail/";
}
}